{*
  Object Pascal simple application manipulation routines
  @Author  Maciej Zagozda (1998-2008)
  @Licence Microsoft Reciprocal License (Ms-RL)
  @Website http://www.codeplex.com/intelitechdelphirtns/
  @Version 2008/04/20 Added documentation support
}

unit ApplicationRoutines;

interface

uses
  Controls,
  Classes,
  Dialogs,
  ExtCtrls,
  Forms,
  Messages,
  SysUtils,
  Windows;

function GetApplicationInfo( byteInformation: Byte ): AnsiString; 

implementation

{*------------------------------------------------------------------------------
  Retrieves metadata for the currently running application

  @param byteInformation specifies type of infomration to be retrieved
         1 - Company Name
         2 - File Description
         3 - File Version
         4 - Internal Name
         5 - Legal Copyright
         6 - Legal Trademarks
         7 - Original File Name
         8 - Product Name
         9 - Product Version
         10 - Comments
  @return Textual value for the requested parameter
  @version 1.0
-------------------------------------------------------------------------------}

function GetApplicationInfo( byteInformation: Byte ): AnsiString;
const
  InfoNum = 10;
  InfoStr : array [1..InfoNum] of AnsiString = ( 'CompanyName', 'FileDescription', 'FileVersion', 'InternalName', 'LegalCopyright', 'LegalTradeMarks', 'OriginalFilename', 'ProductName', 'ProductVersion', 'Comments' );
var
  strnExeName: AnsiString;
  a, Len: Integer;
  charBuffer: PChar;
  charValue: PChar;
begin
  if ( byteInformation < 1 ) or ( byteInformation > InfoNum ) then Exit;

  strnExeName := Application.ExeName;

  a := GetFileVersionInfoSize( PChar( strnExeName ), a );

  if a > 0 then
  begin
    charBuffer := AllocMem( a );
    GetFileVersionInfo( PChar( strnExeName ), 0 , a, charBuffer );

    if VerQueryValue( charBuffer, PChar( 'StringFileInfo\040904E4\' + InfoStr[byteInformation] ), Pointer( charValue ), Len ) then
    begin
      Result := InfoStr[byteInformation];
    end;//if

    FreeMem(charBuffer, a);
  end;//if
end;
end.
